#include "Audio.h"

Audio::Audio(void)
{
	this->state = paNoError;
	this->initialize = false;
	this->inputStream = NULL;
	this->outputStream = NULL;
}


Audio::~Audio(void)
{
}

int		Audio::Initialize()
{
	if (!((this->state = Pa_Initialize()) != paNoError))
		this->initialize = true;
	return this->state;
}

int		Audio::Terminate()
{
	if (!this->initialize)
		return this->state; // definir un etat pour non initialisation

	if (this->state = Pa_Terminate() == paNoError)
		this->initialize = false;
	return this->state;
}

AudioStream		*Audio::OpenStream(StreamType type, void *config, void *callback = NULL, void *data = NULL)
{
	if (!this->initialize)
		return NULL; // definir un etat pour non initialisation
	AudioStream *audioStream = new AudioStream(type);
	audioStream->Open(this, config, callback, data);

	return audioStream;
}

int				Audio::CloseStream(IAudioStream *audioStream)
{
	if (!this->initialize)
		return this->state; // definir un etat pour non initialisation
	if (audioStream){
		audioStream->Close();
	}
	// Supprimer le AudioStream de la liste
	return this->state;
}

bool			Audio::IsInitialized()
{
	return this->initialize;
}